// CoreCalc, a spreadsheet core implementation 

// ----------------------------------------------------------------------
// Copyright (c) 2006-2009 Peter Sestoft and others

// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

//  * The above copyright notice and this permission notice shall be
//    included in all copies or substantial portions of the Software.

//  * The software is provided "as is", without warranty of any kind,
//    express or implied, including but not limited to the warranties of
//    merchantability, fitness for a particular purpose and
//    noninfringement.  In no event shall the authors or copyright
//    holders be liable for any claim, damages or other liability,
//    whether in an action of contract, tort or otherwise, arising from,
//    out of or in connection with the software or the use or other
//    dealings in the software.
// ----------------------------------------------------------------------

using System;
using System.Text;

// Delegate types, exception classes and formula formatting options

namespace CoreCalc {

  // ----------------------------------------------------------------
  // Delegate types used in the recalculation engine


  public delegate Value Applier(Sheet sheet, Expr[] es, int col, int row);

  public delegate R Fun<R>();
  public delegate R Fun<A1, R>(A1 x1);
  public delegate R Fun<A1, A2, R>(A1 x1, A2 x2);
  public delegate R Fun<A1, A2, A3, R>(A1 x1, A2 x2, A3 x3);
  public delegate R Fun<A1, A2, A3, A4, R>(A1 x1, A2 x2, A3 x3, A4 x4);
  public delegate R Fun<A1, A2, A3, A4, A5, R>(A1 x1, A2 x2, A3 x3, A4 x4, A5 x5);
  public delegate R Fun<A1, A2, A3, A4, A5, A6, R>(A1 x1, A2 x2, A3 x3, A4 x4, A5 x5, A6 x6);
  public delegate R Fun<A1, A2, A3, A4, A5, A6, A7, R>(A1 x1, A2 x2, A3 x3, A4 x4, A5 x5, A6 x6, A7 x7);
  public delegate R Fun<A1, A2, A3, A4, A5, A6, A7, A8, R>(A1 x1, A2 x2, A3 x3, A4 x4, A5 x5, A6 x6, A7 x7, A8 x8);
  public delegate R Fun<A1, A2, A3, A4, A5, A6, A7, A8, A9, R>(A1 x1, A2 x2, A3 x3, A4 x4, A5 x5, A6 x6, A7 x7, A8 x8, A9 x9);
  public delegate R Fun<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R>(A1 x1, A2 x2, A3 x3, A4 x4, A5 x5, A6 x6, A7 x7, A8 x8, A9 x9, A10 x10);
  public delegate void Act();
  public delegate void Act<A1>(A1 x1);
  public delegate void Act<A1, A2>(A1 x1, A2 x2);
  public delegate void Act<A1, A2, A3>(A1 x1, A2 x2, A3 x3);
  public delegate void Act<A1, A2, A3, A4>(A1 x1, A2 x2, A3 x3, A4 x4);

  // ----------------------------------------------------------------
  // Exception classes

  class BadFormatException : Exception {
    public BadFormatException(String msg) : base(msg) { }
  }

  class CyclicException : Exception {
    public CyclicException(String msg) : base(msg) { }
  }

  class ImpossibleException : Exception {
    public ImpossibleException(String msg) : base(msg) { }
  }

  class NotImplementedException : Exception {
    public NotImplementedException(String msg) : base(msg) { }
  }

  // ----------------------------------------------------------------
  // Formula formatting options

  public class Formats {
    public enum RefType { A1, C0R0, R1C1 }
    private bool showFormulas = false;
    private RefType refFmt = RefType.A1;
    private char argDelim = ',';
    private char rangeDelim = ':';

    public RefType RefFmt {
      get { return refFmt; }
      set { refFmt = value; }
    }

    public char RangeDelim {
      get { return rangeDelim; }
      set { rangeDelim = value; }
    }

    public char ArgDelim {
      get { return argDelim; }
      set { argDelim = value; }
    }

    public bool ShowFormulas
    {
      get { return showFormulas; }
      set { showFormulas = value; }
    }
  }
}
